package net.joey.httpclient.youku.impl;

import java.text.MessageFormat;

import net.joey.httpclient.youku.VideoAnalyService;
import net.joey.httpclient.youku.utils.JsonUtils;
import net.joey.httpclient.youku.utils.VideoUtils;
import net.sf.json.JSONObject;

public class VideoAnalyServiceKu6Impl implements VideoAnalyService{

	private String apiUrlPre = "http://v.ku6.com/fetch.htm?t=getVideo4Player&vid={0}";
	private String titleJsonKey = "data.t";
	private String picUrlJsonKey = "data.picpath";
	private String outerPlayerUrlPre = "http://player.ku6.com/refer/{0}/v.swf?adss=0";
	@Override
	public Object analyVideo(String oriUrl) {
		String vid = oriUrl.substring(oriUrl.lastIndexOf("/")+1,oriUrl.lastIndexOf("."));
		System.out.println(MessageFormat.format(apiUrlPre, vid));
		JSONObject json = VideoUtils.getUrlJsonContent(MessageFormat.format(apiUrlPre, vid),"UTF-8");
		if(null != json && (Integer)json.get("status") == 1){
			System.out.println("title="+JsonUtils.get(json, titleJsonKey));
			System.out.println("outerPlayerUrl=" + MessageFormat.format(outerPlayerUrlPre, vid));
			System.out.println("picUrl="+JsonUtils.get(json, picUrlJsonKey));
			
			System.out.println(json.toString());
		}
		return null;
	}
	

}
